package com.dlc.beijingrfid.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.dlc.beijingrfid.R;
import com.dlc.beijingrfid.base.BaseActivity;
import com.dlc.commonlibrary.ble.BleWorkerPower;

public class ScanSettingActivity extends BaseActivity {

    @BindView(R.id.power_spinner)
    Spinner mPowerSpinner;
    @BindView(R.id.pro_setting)
    Button mProSetting;
    BleWorkerPower mBleWorkerPower = new BleWorkerPower();
    @BindView(R.id.data)
    TextView mData;

    @Override
    protected int getLayoutID() {
        return R.layout.scan_view;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        initView();
        mBleWorkerPower.setCallback(new BleWorkerPower.ReadCallback() {
            @Override
            public void onReceiveData(String data) {
                mData.setText(data);
                dismissWaitingDialog();
                showOneToast("设置成功");
            }

            @Override
            public void onDeviceDisconnected() {
                dismissWaitingDialog();
                Intent intent = new Intent(ScanSettingActivity.this,MainActivity.class);
                intent.putExtra("type","2");
                startActivity(intent);
                finish();
            }
        });
    }

    private void initView() {
        // mPowerSpinner = (Spinner) findViewById(R.id.power_spinner);
        ArrayAdapter<CharSequence> adapter3 =
            ArrayAdapter.createFromResource(this, R.array.Power_select,
                android.R.layout.simple_spinner_item);
        adapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        mPowerSpinner.setAdapter(adapter3);
        // mPowerSpinner.setSelection(30, true);

        mProSetting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int Power = 0;
                Power =30 - mPowerSpinner.getSelectedItemPosition();
                showWaitingDialog("请等待",true);
                mBleWorkerPower.check(Power);
            }
        });
    }
}
